package com.hesicare.adapter.worker.pull;

import com.hesicare.adapter.entity.ElectronicSignature;
import com.hesicare.adapter.worker.HisWorkManagers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import static com.hesicare.untils.exceptionUtils.exceptionutil.errorTrackSpace;

/**
 * 获取员工电子签名
 *
 * @Author 55097
 * @create 2022/1/4 12:20
 */
@Component
public class PullSginOnWorker {

    protected final static Logger log = LoggerFactory.getLogger(PullSginOnWorker.class);

    @Autowired
    @Resource(name = "jdbcTemplateHis")
    private JdbcTemplate jdbcTemplate;

    public List<ElectronicSignature> readSign(String param) {
        List<ElectronicSignature> result = new ArrayList<ElectronicSignature>();
        StringBuffer sql = new StringBuffer()
                .append("sql");
        try {
            result = this.jdbcTemplate.query(sql.toString(), new RowMapper<ElectronicSignature>() {
                @Override
                public ElectronicSignature mapRow(ResultSet rs, int rowNum) throws SQLException {
                    ElectronicSignature electronicSignature = new ElectronicSignature();
                    String zgid = rs.getString("ZGID");
                    byte[] qmnr = rs.getBytes("QMNR");
                    electronicSignature.setZGID(zgid);
                    electronicSignature.setQMNR(qmnr);
                    return electronicSignature;
                }
            });
        } catch (Exception e) {
            log.error("同步电子签名错误{}", errorTrackSpace(e));
        }
        return result;
    }

}
